package cn.tedu.jdbc;

import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

/**
 * @Author: Miyako
 * @Date: 2024-07-30-16:22
 * @Description: 使用jdbc完成登录功能，登录后对照数据
 */
public class JDBCLogin01 {
    public static void main(String[] args) {
        try(Connection c = new DBUtil().getConnection()){
            Statement statement = c.createStatement();
            Scanner sc = new Scanner(System.in);
            System.out.println("输入你的用户名");
            String username = sc.nextLine();
            System.out.println("输入你的密码");
            String password = sc.nextLine();

            String sql = "Select nickname ,vip from userinfo where username='"
                    +username+"' and password = '"
                    +password+"'";
            ResultSet resultSet = statement.executeQuery(sql);
            String string=null;
            String state = "0";
               resultSet.next() ;
                   string = resultSet.getString("nickname");
                   state = resultSet.getString("vip");

               if (string==null)
            System.out.println("用户或密码错误，没找到这个用户");
               else {
                   if ("1".equals(state))
                   System.out.println("欢迎尊贵的"+string+"vip会员用户登录！");
                   else
                       System.out.println("欢迎普通的"+string+"不是vip会员的穷鬼登录！");
               }

        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}
